package tt.dz.egobus.servicemanager.entities;

import org.hibernate.validator.constraints.NotBlank;
import tt.dz.egobus.base.entity.BaseEntity;

import javax.persistence.*;

/**
 * @author Anson
 * @date 17-3-15
 * @name 租车服务信息
 * @since 1.0.1
 */
@Entity
@Table(name = "bus_service", schema = "servicemanager")
@NamedQueries(value = {@NamedQuery(name = "queryServiceByCodes", query = " select  t  from tt.dz.egobus" + "" +
        ".servicemanager.entities.BusService t   " + " where t.isActive = true  and t.businessCode in " + "" +
        "(:businessCodes)  ")})
public class BusService extends BaseEntity {

    private static final long serialVersionUID = -4796318259974171938L;
    /**
     * 服务名称
     */
    @Column(length = 50)
    @NotBlank(message = "服务名称不能为空")
    private String name;

    /**
     * 基础费用，单位元
     */
    @Column(name = "basics_cost", precision = 10, scale = 2)
    private double basicsCost;

    /**
     * 时间限制，单位分
     */
    @Column(name = "time_limit")
    private int timeLimit;
    /**
     * 里程限制，单位米
     */
    @Column(name = "miles_limit", precision = 18, scale = 6)
    private double milesLimit;

    /**
     * 超时计价时间单位：分
     */
    @Column(name = "time_unit")
    private int timeUnit;

    /**
     * 超时计价价格单位：元
     */
    @Column(name = "price_unit", precision = 10, scale = 2)
    private double priceUnit;


    /**
     * 服务号来自订单系统
     * 一种服务，有且仅有一种服务号对应
     */
    @Column(name = "business_code")
    private int businessCode;


    /**
     * 是否激活
     */
    @Column(name = "is_active")
    private boolean isActive = true;

    /**
     * 服务说明
     */
    @Column(name="service_remark", length = 500)
    private String serviceRemark;


    public BusService() {
    }

    public BusService(String name, double basicsCost, int timeLimit, double milesLimit, int timeUnit, double
            priceUnit, int businessCode) {
        this.name = name;
        this.basicsCost = basicsCost;
        this.timeLimit = timeLimit;
        this.milesLimit = milesLimit;
        this.timeUnit = timeUnit;
        this.priceUnit = priceUnit;
        this.businessCode = businessCode;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getBasicsCost() {
        return basicsCost;
    }

    public void setBasicsCost(double basicsCost) {
        this.basicsCost = basicsCost;
    }

    public int getTimeLimit() {
        return timeLimit;
    }

    public void setTimeLimit(int timeLimit) {
        this.timeLimit = timeLimit;
    }

    public double getMilesLimit() {
        return milesLimit;
    }

    public void setMilesLimit(double milesLimit) {
        this.milesLimit = milesLimit;
    }

    public int getTimeUnit() {
        return timeUnit;
    }

    public void setTimeUnit(int timeUnit) {
        this.timeUnit = timeUnit;
    }

    public double getPriceUnit() {
        return priceUnit;
    }

    public void setPriceUnit(double priceUnit) {
        this.priceUnit = priceUnit;
    }

    public int getBusinessCode() {
        return businessCode;
    }

    public void setBusinessCode(int businessCode) {
        this.businessCode = businessCode;
    }

    public boolean isActive() {
        return isActive;
    }

    public boolean getIsActive() {
        return isActive;
    }

    public void setIsActive(boolean isActive) {
        isActive = isActive;
    }

    public String getServiceRemark() {
        return serviceRemark;
    }

    public void setServiceRemark(String serviceRemark) {
        this.serviceRemark = serviceRemark;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        BusService that = (BusService) o;

        if (Double.compare(that.basicsCost, basicsCost) != 0) return false;
        if (timeLimit != that.timeLimit) return false;
        if (Double.compare(that.milesLimit, milesLimit) != 0) return false;
        if (timeUnit != that.timeUnit) return false;
        if (Double.compare(that.priceUnit, priceUnit) != 0) return false;
        if (businessCode != that.businessCode) return false;
        if (isActive != that.isActive) return false;
        if (name != null ? !name.equals(that.name) : that.name != null) return false;
        return serviceRemark != null ? serviceRemark.equals(that.serviceRemark) : that.serviceRemark == null;
    }

    @Override
    public int hashCode() {
        int result;
        long temp;
        result = name != null ? name.hashCode() : 0;
        temp = Double.doubleToLongBits(basicsCost);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        result = 31 * result + timeLimit;
        temp = Double.doubleToLongBits(milesLimit);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        result = 31 * result + timeUnit;
        temp = Double.doubleToLongBits(priceUnit);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        result = 31 * result + businessCode;
        result = 31 * result + (isActive ? 1 : 0);
        result = 31 * result + (serviceRemark != null ? serviceRemark.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "BusService{" + "name='" + name + '\'' + ", basicsCost=" + basicsCost + ", timeLimit=" + timeLimit +
                ", milesLimit=" + milesLimit + ", timeUnit=" + timeUnit + ", priceUnit=" + priceUnit + ", " +
                "businessCode=" + businessCode + ", isActive=" + isActive + ", serviceRemark='" + serviceRemark +
                '\'' + '}';
    }
}
